package gov.army.workshop.model;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.compass.annotations.Searchable;
import org.compass.annotations.SearchableId;
import org.compass.annotations.SearchableProperty;


@Entity
@Table(name="EQMS_PAYMENT")
@Searchable
public class Payment {

	public static enum PaymentType {
        Issue, Receipt
    }
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -6783481046546301029L;
	private Long id;
	private String voucherNo;
	private Date date;
	private int quantity;
	private PaymentType type;
	private Workorder workorder;
	
	@Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @SearchableId
    public Long getId() {
        return id;
    }
    
	/**
	 * @param id the id to set
	 */
	public void setId(Long id) {
		this.id = id;
	}
	/**
	 * @return the type
	 */
	@Column(name = "PAYMENT_TYPE")
    @SearchableProperty
	public PaymentType getType() {
		return type;
	}

	/**
	 * @param type the type to set
	 */
	public void setType(PaymentType type) {
		this.type = type;
	}


	/**
	 * @return the voucherNo
	 */
	@Column(name = "VOUCHER_NO", nullable = false)
    @SearchableProperty
	public String getVoucherNo() {
		return voucherNo;
	}

	/**
	 * @return the date
	 */
	@Column(name = "PAYMENT_DATE", nullable = false)
    @SearchableProperty
	public Date getDate() {
		return date;
	}

	/**
	 * @return the quantity
	 */
	@Column(name = "QUANTITY", nullable = false)
    @SearchableProperty
	public int getQuantity() {
		return quantity;
	}

	/**
	 * @return the workorder
	 */
	@ManyToOne( fetch=FetchType.EAGER )
    @JoinColumn(name="WORKORDER_ID", nullable=false)
	public Workorder getWorkorder() {
		return workorder;
	}

	/**
	 * @param workorder the workorder to set
	 */
	public void setWorkorder(Workorder workorder) {
		this.workorder = workorder;
	}
	/**
	 * @param voucherNo
	 *            the voucherNo to set
	 */
	public void setVoucherNo(String voucherNo) {
		this.voucherNo = voucherNo;
	}

	/**
	 * @param date
	 *            the date to set
	 */
	public void setDate(Date date) {
		this.date = date;
	}

	/**
	 * @param quantity
	 *            the quantity to set
	 */
	public void setQuantity(int quantity) {
		this.quantity = quantity;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Payment other = (Payment) obj;
		if (date == null) {
			if (other.date != null)
				return false;
		} else if (!date.equals(other.date))
			return false;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (quantity != other.quantity)
			return false;
		if (type != other.type)
			return false;
		if (voucherNo == null) {
			if (other.voucherNo != null)
				return false;
		} else if (!voucherNo.equals(other.voucherNo))
			return false;
		return true;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((date == null) ? 0 : date.hashCode());
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result + quantity;
		result = prime * result + ((type == null) ? 0 : type.hashCode());
		result = prime * result
				+ ((voucherNo == null) ? 0 : voucherNo.hashCode());
		return result;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "Payment [id=" + id + ", voucherNo=" + voucherNo + ", date="
				+ date + ", quantity=" + quantity + ", type=" + type + "]";
	}
}
